]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dbusService: Exempt org.gnome.Shell from sender tracking
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 13 Dec 2023 00:11:52 +0000 (01:11 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 13 Dec 2023 00:27:51 +0000 (01:27 +0100)
If an interface has any signals, we don't want to auto-shutdown
while a caller is still connected to a signal.

Unfortunately we can't tell whether there are any signal connections,
so we track all callers instead, and keep the service alive while
any of them is still on the bus.

For services that we call from gnome-shell itself - like screencasts
or extensions - this has the unintended side effect of effectively
disabling auto-shutdown.

Address this by exempting the org.gnome.Shell name from sender
tracking.

Services that we expect to keep running for the lifetime of the
shell already disable auto-shutdown, so the only downside is a
small startup delay to resolve the well-known shell name.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7250

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3052>

js/dbusServices/dbusService.js

index 1b1f7c6e2754f97703d43012f9c3a1879a892aee..422ef60e24c2ed911475bb5349f3d2cd1082812a 100644 (file)
@@ -21,6 +21,8 @@ export class ServiceImplementation {
         this._senders = new Map();
         this._holdCount = 0;
 
+        this._shellName = this._getUniqueShellName();
+
         this._hasSignals = this._dbusImpl.get_info().signals.length > 0;
         this._shutdownTimeoutId = 0;
 
@@ -115,6 +117,9 @@ export class ServiceImplementation {
         if (this._senders.has(sender))
             return;
 
+        if (sender === this._shellName)
+            return; // don't track the shell
+
         this.hold();
         this._senders.set(sender,
             this._dbusImpl.get_connection().watch_name(
@@ -148,6 +153,26 @@ export class ServiceImplementation {
             that._queueShutdownCheck();
         };
     }
+
+    _getUniqueShellName() {
+        try {
+            const res = Gio.DBus.session.call_sync(
+                'org.freedesktop.DBus',
+                '/org/freedesktop/DBus',
+                'org.freedesktop.DBus',
+                'GetNameOwner',
+                new GLib.Variant('(s)', ['org.gnome.Shell']),
+                null,
+                Gio.DBusCallFlags.NONE,
+                -1,
+                null);
+            const [name] = res.deepUnpack();
+            return name;
+        } catch (e) {
+            console.warn(`Failed to resolve shell name: ${e.message}`);
+            return '';
+        }
+    }
 }
 Signals.addSignalMethods(ServiceImplementation.prototype);